package com.aiwu.memory;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiwu.BaseLazyFragment;

import org.citra.citra_emu.R;

/**
 * 加载
 */
public class MemoryLoadingFragment extends BaseLazyFragment implements OnActionCallback {
    private static final String TAG = MemoryLoadingFragment.class.getName();
    private Animation mLoadingAnim;
    private ImageView mIvLoading;
    private TextView tvLoadingTip;

    @Override
    protected void lazyLoad() {
        startLoadingAnim();
    }

    @Override
    protected void stopLoad() {
        stopLoadingAnim();
    }

    @Override
    protected int initContentView() {
        return R.layout.fragment_memory_loading;
    }

    @Override
    protected Boolean repeatedLoad() {
        return true;
    }

    @Override
    public void onDestroy() {
        if (mLoadingAnim != null)
            mLoadingAnim.cancel();
        if (mIvLoading != null)
            mIvLoading.clearAnimation();
        MemoryManager.getInstance().removeOnActionCallback(this);
        super.onDestroy();
    }

    @Override
    protected void initView(View view) {
        mIvLoading = view.findViewById(R.id.iv_loading);
        tvLoadingTip = view.findViewById(R.id.tv_tip);
        MemoryManager.getInstance().addOnActionCallback(this);
    }

    private void startLoadingAnim() {
        if (mLoadingAnim == null) {
            mLoadingAnim = AnimationUtils.loadAnimation(getContext(), com.aiwu.R.anim.loading_anim);
        }
        if (mIvLoading != null) {
            mIvLoading.startAnimation(mLoadingAnim);
        }
    }

    private void stopLoadingAnim() {
        if (mIvLoading != null) {
            mIvLoading.clearAnimation();
        }
    }

    @Override
    public void onShowKeyboard() {

    }

    @Override
    public void onCloseKeyboard() {

    }
}
